import 'parse_factory.dart';
import 'rule.dart';

class AndRule extends Rule {
  List<Rule> andRules;

  AndRule(this.andRules);

  @override
  String toString() {
    String string = "";
    for (var rule in andRules) string += rule.toString();
    return "{andRules : $string}";
  }
}

class AndParser extends IParser<AndRule> {
  AndParser(AndRule rule) : super(rule);

  //todo 拼接方式??
  @override
  Future<String> getString(String content, {Map<String, dynamic>? valueMap}) async {
    var result = '';
    for (var rule in rule.andRules) {
      var append = await ParseFactory.getParser(rule).getString(content, valueMap: valueMap);
      result = '$result$append\\n';
    }
    return result;
  }

  @override
  Future<List<String>> getStringList(String content, {Map<String, dynamic>? valueMap}) async {
    var result = <String>[];
    for (var rule in rule.andRules) {
      var append = await ParseFactory.getParser(rule).getStringList(content, valueMap: valueMap);
      result.addAll(append);
    }
    return result;
  }
}
